package com.lanou.zakerproject.subscribe;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.lanou.zakerproject.R;
import com.lanou.zakerproject.base.VolleySingleton;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/1/15.
 */
public class SearchAdapter extends BaseAdapter {
    private Context context;
    private ChannelSearch channelSearch;

    public SearchAdapter(Context context, ChannelSearch channelSearch) {
        this.context = context;
        this.channelSearch = channelSearch;
    }

    @Override
    public int getCount() {
        return channelSearch.getData().getList().size();
    }

    @Override
    public Object getItem(int position) {
        return channelSearch.getData().getList().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder myViewHolder;
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_find_channel,parent,false);
            myViewHolder = new MyViewHolder(convertView);
            convertView.setTag(myViewHolder);
        }else {
            myViewHolder = (MyViewHolder) convertView.getTag();
        }
        myViewHolder.textView.setText(channelSearch.getData().getList().get(position).getTitle());
        ImageLoader.ImageListener listener = ImageLoader.getImageListener(myViewHolder.img_icon, R.mipmap.ic_launcher, R.mipmap.default_img_nonet);
        VolleySingleton.getImageLoader().get(channelSearch.getData().getList().get(position).getPic(), listener);
        return convertView;
    }

    class MyViewHolder {
        private TextView textView;
        private ImageView img_icon;
        public MyViewHolder(View view) {
            textView = (TextView) view.findViewById(R.id.item_find_channel_tv);
            img_icon = (ImageView) view.findViewById(R.id.item_find_channel_icon);
        }
    }
}
